package com.shop.loan.proxy;//package com.shop.loan.proxy;
//
//import com.shop.loan.util.Util;
//import org.springframework.stereotype.Service;
//import xyz.erupt.annotation.fun.DataProxy;
//import xyz.erupt.annotation.query.Condition;
//import xyz.erupt.upms.service.EruptUserService;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.Collection;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
//@Service
//public class ChannelStatisticsViewProxy implements DataProxy<ChannelStatisticsView> {
//
//    @Resource
//    EruptUserByMybatisMapper eruptUserByMybatisMapper;
//
//    @Resource
//    EruptUserService eruptUserService;
//
//    @Resource
//    UserByMybatisMapper userByMybatisMapper;
//
//    @Resource
//    SignOrderByMybatisMapper signOrderByMybatisMapper;
//
//    @Resource
//    Util util;
//
//    @Override
//    public String beforeFetch(List<Condition> conditions) {
//        Iterator<Condition> iterator = conditions.iterator();
//        while (iterator.hasNext()) {
//            Condition condition = iterator.next();
//            if ("createTime".trim().equals(condition.getKey())) {
//                iterator.remove();
//            }
//        }
//
//        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
//        if (eruptUserByMybatis != null && eruptUserByMybatis.getChannelId() != null) {
//            return "ChannelStatisticsView.id = " + eruptUserByMybatis.getChannelId();
//        }
//        return null;
//    }
//
//    @Override
//    public void afterFetch(Collection<Map<String, Object>> list) {
//        String createTimeStart = util.getSearchParam("createTime", 0);
//        String createTimeEnd = util.getSearchParam("createTime", 1);
//        for (Map<String, Object> stringObjectMap : list) {
//            Long channelId = Long.valueOf(stringObjectMap.get("id").toString());
//            //出借人
//            Integer userNum = userByMybatisMapper.selectTypeByChannel(channelId);
//
//            //全部订单数
//            Integer orderNumByTotal = signOrderByMybatisMapper.selectNumByChannel(channelId, null, createTimeStart, createTimeEnd);
//            BigDecimal orderMoneyByTotal = signOrderByMybatisMapper.selectMoneyByChannel(channelId, null, createTimeStart, createTimeEnd);
//
//            //已结束订单数
//            Integer orderNumByEnd = signOrderByMybatisMapper.selectNumByChannel(channelId, OrderStatus.end.getStatus(), createTimeStart, createTimeEnd);
//            BigDecimal orderMoneyByEnd = signOrderByMybatisMapper.selectMoneyByChannel(channelId, OrderStatus.end.getStatus(), createTimeStart, createTimeEnd);
//
//            //已签署订单数
//            Integer orderNumBySign = signOrderByMybatisMapper.selectNumByChannel(channelId, OrderStatus.underway.getStatus(), createTimeStart, createTimeEnd);
//            BigDecimal orderMoneyBySign = signOrderByMybatisMapper.selectMoneyByChannel(channelId, OrderStatus.underway.getStatus(), createTimeStart, createTimeEnd);
//
//            orderNumByEnd = orderNumByEnd == null ? 0 : orderNumByEnd;
//            orderMoneyByEnd = orderMoneyByEnd == null ? BigDecimal.ZERO : orderMoneyByEnd;
//            orderNumBySign = orderNumBySign == null ? 0 : orderNumBySign;
//            orderMoneyBySign = orderMoneyBySign == null ? BigDecimal.ZERO : orderMoneyBySign;
//
//            stringObjectMap.put("userNum", userNum == null ? 0 : userNum);
//            stringObjectMap.put("orderNumByTotal", orderNumByTotal == null ? 0 : orderNumByTotal);
//            stringObjectMap.put("orderMoneyByTotal", orderMoneyByTotal == null ? BigDecimal.ZERO : orderMoneyByTotal);
//            stringObjectMap.put("orderNumByEnd", orderNumByEnd);
//            stringObjectMap.put("orderMoneyByEnd", orderMoneyByEnd);
//            stringObjectMap.put("orderNumBySign", orderNumBySign + orderNumByEnd);
//            stringObjectMap.put("orderMoneyBySign", orderMoneyByEnd.add(orderMoneyBySign));
//        }
//    }
//
//}
